package com.zy.ServletListener;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

//@WebListener,注解方式，注册监听器
public class listenerDemo1 implements ServletContextListener
{
    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent)
    {
        System.out.println("监听器被创建---");
        ServletContext servletContext = servletContextEvent.getServletContext();
        String applicationContext = servletContext.getInitParameter("applicationContext");
        String realPath = servletContext.getRealPath(applicationContext);
        FileInputStream fileInputStream = null;
        try
        {
            fileInputStream = new FileInputStream(realPath);
        } catch (FileNotFoundException e)
        {
            e.printStackTrace();
        }
        System.out.println(fileInputStream);
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent)
    {
        System.out.println("监听器被销毁----");
    }
}
